package cn.com.bluemoon.daps.api.sys.factory;

import cn.com.bluemoon.daps.api.sys.RemoteSysOperateLogService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.system.dto.OperateLogPageDTO;
import cn.com.bluemoon.daps.system.entity.DapOperateLog;
import com.baomidou.mybatisplus.core.metadata.IPage;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteSysOperateLogServiceFallbackFactory implements FallbackFactory<RemoteSysOperateLogService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteSysOperateLogServiceFallbackFactory.class);


    @Override
    public RemoteSysOperateLogService create(Throwable throwable) {
        log.error("系统服务调用失败:{}", throwable.getMessage());
        return new RemoteSysOperateLogService() {
            @Override
            public ResultBean<IPage<DapOperateLog>> operateLogPage(OperateLogPageDTO dto) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "分页获取操作日志失败！");
            }

            @Override
            public ResultBean<Boolean> addOperateLog(DapOperateLog operateLog) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, DapsApiSystem.PROD_SERVICE, "新增操作日志失败！");
            }
        };
    }
}
